package com.huawei.appgallery.appcomment.ui.view;

import android.app.Activity;
import android.content.Context;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import com.huawei.appgallery.appcomment.impl.bean.AddCommentReplyResBean;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import huawei.widget.HwCounterTextLayout;
import java.lang.ref.WeakReference;
import o.azb;
import o.bcg.a;
import o.bcg.c;
import o.bcg.d;
import o.bcg.h;
import o.bcs;
import o.bdo;
import o.bdp;
import o.bdr;
import o.bdz;
import o.bmt;
import o.ckt;
import o.ckv;
import o.BaseRequest;

public class PublishReplyView extends LinearLayout implements OnClickListener, TextWatcher {
    private String ʻ;
    private String ʼ;
    private View ʽ;
    private ImageView ˊ;
    private Context ˋ;
    private HwCounterTextLayout ˎ;
    private ReplyEditText ˏ;
    private View ॱ;
    private b ॱॱ;
    private String ᐝ;

    public interface b {
        void ˊ(String str);

        void ॱ();
    }

    static class e implements IServerCallBack {
        private final b ˊ;
        private WeakReference<Context> ˎ;

        public e(Context context, b bVar) {
            this.ˊ = bVar;
            this.ˎ = new WeakReference(context);
        }

        public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
        }

        public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
            String str = "";
            Context context = (Context) this.ˎ.get();
            if (context != null) {
                CharSequence string;
                if (responseBean == null) {
                    string = context.getString(h.ꜟ);
                } else if ((responseBean instanceof AddCommentReplyResBean) && responseBean.getResponseCode() == 0) {
                    if (responseBean.getRtnCode_() == 0) {
                        this.ˊ.ˊ(((bcs) o_cvu).ˊ());
                        string = context.getString(h.ˎˏ);
                    } else if (1 == responseBean.getRtnCode_()) {
                        string = context.getString(h.ՙ);
                    } else if (3 == responseBean.getRtnCode_()) {
                        string = context.getString(h.ߵ);
                    } else if (2 == responseBean.getRtnCode_()) {
                        string = context.getString(h.ߴ);
                    } else if (4 == responseBean.getRtnCode_()) {
                        bdr.ˋ();
                        string = context.getString(h.ˋᐝ);
                    } else {
                        string = context.getString(h.ˋᐝ);
                    }
                } else if (responseBean.getResponseCode() == 3) {
                    string = context.getString(h.ᐝʽ);
                } else {
                    string = context.getString(h.ꜟ);
                }
                if (!TextUtils.isEmpty(string)) {
                    ckv.ˎ(string, 0);
                }
            }
        }
    }

    public PublishReplyView(Context context) {
        this(context, null);
    }

    public PublishReplyView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.ᐝ = "";
        this.ˋ = context;
        this.ॱ = ((LayoutInflater) context.getSystemService("layout_inflater")).inflate(d.ˊॱ, this, true);
        azb.ˏ(this.ॱ);
        this.ˏ = (ReplyEditText) this.ॱ.findViewById(o.bcg.e.ﾞॱ);
        this.ˎ = (HwCounterTextLayout) this.ॱ.findViewById(o.bcg.e.ʻʽ);
        this.ˊ = (ImageView) this.ॱ.findViewById(o.bcg.e.ꓸ);
        this.ʽ = this.ॱ.findViewById(o.bcg.e.ᐝᐝ);
        this.ˏ.addTextChangedListener(this);
        this.ʽ.setOnClickListener(new ckt(this));
        setBackgroundColor(getResources().getColor(a.ॱ));
        this.ˎ.setPaddingRelative(0, 0, 0, 0);
    }

    public void setOnReplyCommitClickListener(b bVar) {
        if (bVar != null) {
            this.ॱॱ = bVar;
        }
    }

    public void setCommentId(String str) {
        this.ʻ = str;
    }

    public void setReplyID(String str) {
        this.ʼ = str;
    }

    public void setContentHint(String str) {
        this.ˏ.setText("");
        this.ˏ.setHint(str);
    }

    public void setUserName(String str) {
        this.ᐝ = str;
    }

    public ReplyEditText ˋ() {
        return this.ˏ;
    }

    public void setContent(String str) {
        this.ˏ.setText(str);
    }

    public void setEnabled(boolean z) {
        this.ˊ.setEnabled(z);
    }

    public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
    }

    public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        if (charSequence == null || TextUtils.isEmpty(charSequence.toString())) {
            this.ˊ.setImageResource(c.ॱॱ);
        } else {
            this.ˊ.setImageResource(c.ॱ);
        }
    }

    public void afterTextChanged(Editable editable) {
    }

    public void onClick(View view) {
        if (!bmt.ˊ(this.ˋ)) {
            ckv.ˎ(this.ˋ.getString(h.ᐝʽ), 0);
        } else if (view != null) {
            new bdr((Activity) view.getContext(), new bdz(this) {
                final /* synthetic */ PublishReplyView ˋ;

                {
                    this.ˋ = r1;
                }

                public void ˊ() {
                    this.ˋ.ˊ();
                }

                public void ˋ() {
                }
            }).ˎ();
        }
    }

    private String ˎ() {
        if (this.ˏ != null) {
            return this.ˏ.getText().toString().trim();
        }
        return null;
    }

    public void ˊ() {
        String ˎ = ˎ();
        if (ˎ == null || TextUtils.isEmpty(ˎ.trim())) {
            ckv.ˎ(this.ˋ.getString(h.ߺ), 0);
            return;
        }
        View currentFocus = ((Activity) this.ˋ).getCurrentFocus();
        if (currentFocus != null) {
            currentFocus.clearFocus();
        }
        this.ॱॱ.ॱ();
        if (bdo.ˋ(bdo.d.COMMENT_REPLY, ˎ)) {
            ckv.ˎ(this.ˋ.getString(h.ՙ), 0);
            return;
        }
        new bdp().ˊ(this.ˋ, this.ʻ, this.ʼ, this.ᐝ, ˎ, new e(this.ˋ, this.ॱॱ));
        this.ˏ.setText("");
    }
}
